using System;
using Clandestine.Base;
using Clandestine.Engines.Field;
using Qyoto;

namespace Shlick
{
	public class LayerGroupMenu : QObject, IContextMenu
	{
		public MapDocument MapDocument { get; private set; }
		public LayerGroup LayerGroup { get; private set; }
		public LayerTreeView TreeView { get; private set; }
		private QMenu menu;
		
		public LayerGroupMenu (LayerTreeView parent, MapDocument mapDocument, LayerGroup layerGroup)
		{
			this.MapDocument = mapDocument;
			this.LayerGroup = layerGroup;
			this.TreeView = parent;
			
			// Make menu!
			menu = new QMenu(parent);
			menu.AddAction(new QIcon(":/tango/scalable/actions/list-add.svg"), "Add New Layer", this, SLOT("onAddSelect()"));
			menu.AddSeparator();
			menu.AddAction(new QIcon(":/tango/scalable/status/weather-clear.svg"), "Show All Layers", this, SLOT("onShowSelect()"));
			menu.AddAction(new QIcon(":/tango/scalable/status/weather-overcast.svg"), "Hide All Layers", this, SLOT("onHideSelect()"));
		}
		
		public void Show()
		{
			menu.Exec(QCursor.Pos());
		}
		
		[Q_SLOT("onAddSelect()")]
		private void onAddSelect()
		{	
			Log.i("Command needed.");
			TreeView.BeginChange();
			LayerGroup.AddLayer(new Layer(LayerGroup));
			TreeView.EndChange();
		}
		
		[Q_SLOT("onShowSelect()")]
		private void onShowSelect()
		{
			Log.i("Command needed.");
			TreeView.BeginChange();
			LayerGroup.Visible = true;
			TreeView.EndChange();
		}
				
		[Q_SLOT("onHideSelect()")]
		private void onHideSelect()
		{
			Log.i("Command needed.");
			TreeView.BeginChange();
			LayerGroup.Visible = false;
			TreeView.EndChange();
		}
	}
}

